#!BPY

""" Registration info for Blender menus:
Name: 'ConSpot'
Blender: 241
Group: 'Object'
Tooltip: 'Creates an automatic spotlight rig that is contrained to an empty'
"""

# --------------------------------------------------------------------------
# ***** BEGIN BSD LICENCE BLOCK *****
# Copyright (c) 2009-2010, Ted Gocek
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#    * Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
#    * Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in the
#      documentation and/or other materials provided with the distribution.
#    * Neither the name of the Libero (Libe) Spagnolini nor the
#      names of its contributors may be used to endorse or promote products
#      derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY 'Ted Gocek' IS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Libero (Libe) Spagnolini BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ***** END BSD LICENCE BLOCK *****
# --------------------------------------------------------------------------
# Original code written by Justin Dailey
#
# Bug fix - scn.update() by Ted Gocek
# Script group addition by Ted Gocek - makes the script load into Blender on startup


__author__ = "Justin Dailey"
__url__ = ("")
__version__ = "0.3"

__bpydoc__ = """\
Creates an automatic spotlight rig that is contrained to an empty

Inspired by Pixar screencasts using similar method.
"""

import Blender

# get the current scene
scn = Blender.Scene.GetCurrent()      

# create an empty object
empty = scn.objects.new("Empty")
empty.loc = Blender.Window.GetCursorPos()

# create lamp data
lamp = Blender.Lamp.New('Spot')

# create new object with lamps data
lampob = scn.objects.new(lamp)

lampob.loc = empty.loc
lampob.LocZ = empty.LocZ + 10

# constrain
tt = lampob.constraints.append(Blender.Constraint.Type.TRACKTO)

# adjust settings
tt[Blender.Constraint.Settings.TARGET] = empty
tt[Blender.Constraint.Settings.TRACK] = Blender.Constraint.Settings.TRACKNEGZ
tt[Blender.Constraint.Settings.UP] = Blender.Constraint.Settings.UPY

scn.update()
Blender.Redraw()